home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / VIEWS.ZIP;1 / CVDZIP.EXE / CVABOUT.CPP next >
Encoding:
C/C++ Source or Header  |  1992-10-10  |  3.6 KB  |  178 lines

  1. /*
  2.     cvabout.cpp
  3.  
  4.     Bouncing About Box
  5.  
  6.     C++/Views 2.0 Demo
  7.     Copyright (c) 1992, by Liant Software Corp.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "cvabout.h"
  15. #include "cvbounce.h"
  16. #include "pushbttn.h"
  17. #include "port.h"
  18. #include "bitmap.h"
  19. #include "timer.h"
  20. #include "cvhow.h"
  21.  
  22. BounceAbout::BounceAbout(VWindow *pwin) :
  23.     bouncers(5), 
  24.     VDialog(92, 77, 150, 100, pwin, StyleTitle | StyleCloseBox)
  25. {
  26.     setBackground(new VBrush(WHITE));
  27.     setTitle("About");
  28.  
  29.     /* create About button */
  30.     VPushButton *aboutbttn;
  31.     aboutbttn = new VPushButton(VFrame(170, 120, 120, 30), this, StyleDefaultButton, "About");
  32.     aboutbttn->uponClick(this, methodOf(BounceAbout, aboutBtn));
  33.  
  34.     /* create OK button */
  35.     VPushButton *okbttn;
  36.     okbttn = new VPushButton(VFrame(170, 160, 120, 30), this, StyleDefaultButton, "Ok");
  37.     setDefButton(okbttn);
  38.     okbttn->uponClick(this, methodOf(VDialog, ok));
  39.  
  40.     /* place Bouncer objects into collection */
  41.     bouncers.add(new Bouncer("C++/Views",                 10, 20));
  42.     bouncers.add(new Bouncer("Demo Program v2.0",         10, 40));
  43.     bouncers.add(new Bouncer("Copyright © 1992",         10, 60));
  44.     bouncers.add(new Bouncer("by Liant Software Corp.",     10, 80));
  45.  
  46.     /* create an event timer */
  47.     timer = new VTimer;
  48.     timer->uponTimeout(this, methodOf(BounceAbout, startBouncing));
  49.     timer->start(4000);
  50. }
  51.  
  52. BounceAbout::~BounceAbout()
  53. {
  54.     /* destroy background brush */
  55.     delete getBackground();
  56.  
  57.     delete timer;
  58.  
  59.     bouncers.freeContents();
  60. }
  61.  
  62. boolean BounceAbout::free()
  63. {
  64.     delete this;
  65.     return(TRUE);
  66. }
  67.  
  68. boolean BounceAbout::paint()
  69. /*
  70.     Paint the contents of the About box.
  71. */
  72. {
  73.     VPort port(this);
  74.     VPen  pn(BLACK);
  75.     VBitMap bmap("LIANT");
  76.  
  77.     port.open();
  78.     port.usePen(&pn);
  79.  
  80.     port.drawBitMap(&bmap, 165, 20);
  81.  
  82.     int i, count;
  83.     Bouncer *bnc;
  84.  
  85.     count = (int)bouncers.count();
  86.     for (i = 0; i < count; i++) {
  87.         bnc = (Bouncer *)bouncers.idAt(i);
  88.         if (bnc) {
  89.             pn.color((i % 2) ? RED : BLACK);
  90.             port.wrtText(bnc->str, bnc->curX, bnc->curY);
  91.         }
  92.     }
  93.  
  94.     port.close();
  95.     return (TRUE);
  96. }
  97.  
  98. boolean BounceAbout::startBouncing()
  99. /*
  100.     Called at the end of the initial timeout...
  101. */
  102. {
  103.     /* change the timer call back */
  104.     timer->uponTimeout(this, methodOf(BounceAbout, bounceThem));
  105.     timer->start(50);
  106.     return(TRUE);
  107. }
  108.  
  109. boolean BounceAbout::bounceThem()
  110. /*
  111.     Called by the timer, moves the bouncing objects
  112. */
  113. {
  114.     VPort port(this);
  115.     VPen  pn;
  116.  
  117.     int        x, y, w, h;
  118.     getArea(&x, &y, &w, &h);
  119.  
  120.     port.open();
  121.     port.usePen(&pn);
  122.  
  123.     int i, count;
  124.     Bouncer *bnc;
  125.  
  126.     count = (int)bouncers.count();
  127.     for (i = 0; i < count; i++) {
  128.         bnc = (Bouncer *)bouncers.idAt(i);
  129.         if (bnc) {
  130.             /* erase old, old message */
  131.             pn.color(WHITE);
  132.             port.wrtText(bnc->str, bnc->curX, bnc->oldY2);
  133.  
  134.             /* erase old message */
  135.             pn.color(LightGray);
  136.             port.wrtText(bnc->str, bnc->curX, bnc->curY);
  137.  
  138.             bnc->oldY2 = bnc->oldY;
  139.             bnc->oldY = bnc->curY;
  140.             bnc->curY += bnc->yVel;
  141.             bnc->yVel = (bnc->curY > (h - 10) && bnc->yVel > 0)
  142.                              ? -bnc->yVel : bnc->yVel + 1;
  143.         }
  144.     }
  145.  
  146.     /* now draw the real text (do last for maximum visibility */
  147.     for (i = 0; i < count; i++) {
  148.         bnc = (Bouncer *)bouncers.idAt(i);
  149.         if (bnc) {
  150.             /* draw message at new location */
  151.             pn.color((i % 2) ? RED : BLACK);
  152.             port.wrtText(bnc->str, bnc->curX, bnc->curY);
  153.         }
  154.     }
  155.  
  156.     port.close();
  157.  
  158.     return(TRUE);
  159. }
  160.  
  161. boolean BounceAbout::aboutBtn(VButton *b)
  162. /*
  163.     "About" button pressed
  164. */
  165. {
  166.     /* Display a "How-does-it-work" dialog */
  167.     HowView    how(this, "About:About", "cvabout.cpp");
  168.  
  169.     /* make the about how visible */
  170.     how.show();
  171.  
  172.     /* activate the dialog (as a modal dialog) */
  173.     how.modal();
  174.  
  175.     return(TRUE);
  176. }
  177.  
  178.